package com.bzframework.example.kafka;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @Author bingzhong
 * @Date 2025/9/15
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class KafkaProducer {

    private final KafkaTemplate<String, String> kafkaTemplate;

    public void sendNoKeyMessage(String topic, String message) {

        kafkaTemplate.send(topic, message)
                     .thenAccept(result -> {
                         log.info("result:{}", result.toString());
                     });

    }

    public void sendKeyMessage(String topic, String key, String message) {

        kafkaTemplate.send(topic, key, message)
                .thenAccept(result -> {
                    log.info("result:{}", result.toString());
                });
    }

}
